var type="loan"
import {loanReader} from "../../apis/gyt"
import {chooseMedia} from "../../utils/sfz"
Page({
  data: {
    switchModeValue:true,
    idcard_res:{},
    url:"",
    rdid:""
  },
 async loanReader(rdid){
   console.log(rdid)
  var res=await loanReader(rdid);
  wx.setStorageSync('curreader', res.reader);
  wx.setStorageSync('curreaderandloans', res);
  console.log(res);
  if(!res.right){
    wx.showToast({title: res.msg,icon: 'error',duration: 1500});
    return;
  }
  if(type=="loan"){
  wx.navigateTo({
    url: `/pages/loan/loan?rdid=${res.reader.rdid}`
  })
}
else{
  wx.navigateTo({
    url: `/pages/renew/renew?rdid=${res.reader.rdid}`
  })
}
 },
 scanqr(){
  wx.scanCode({
    success: (res) => this.loanReader(res.result)
  })
 },
 goToConfirm() {
  debugger;
  this.loanReader(this.data.rdid);
},
clickCurReader(){
  this.loanReader("421023199104042972");
},
switchMode(){
  var flag=this.data.switchModeValue;
  this.setData({switchModeValue:!flag})
},
async chooseMedia(){
  wx.showLoading({title: '正在识别身份证'})
    var r=await  chooseMedia().catch(err=>{
      wx.showToast({
        title: '拍摄照片识别出错',
      });
      return {};
    });
    if(r.idcard_res){
      this.setData({idcard_res:r.idcard_res,url:r.tempFilePath,rdid:r.idcard_res.id.text})
      await this.loanReader(r.idcard_res.id.text);
    }
    wx.hideLoading();
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(option) {
    type=option.type;
    console.log(option.type);
  }

  
})

